import myRequest from '../request.js'

import dicts from '@/config/dicts.js'


//发起微信支付
export const wechatPayment = (WECHAT, orderType, sn, code) => {
	let clientType = ""
	return new Promise((resolve, reject) => {
		// #ifdef MP-WEIXIN
		clientType = 'MP'
		// #endif
		// #ifdef MP-TOUTIAO
		clientType = 'DOUYIN_MP'
		// #endif
		// #ifndef MP
		clientType = 'APP'
		// #endif
		myRequest(dicts.buyer +
			`/purchaser/payment/cashier/pay/${WECHAT}/${clientType}?orderType=${orderType}&sn=${sn}&code=${code}`, 'get')
			.then(res => {
				resolve(res)
			}).catch((err) => {
				reject(err)
			})
	})
}

// 创建余额充值订单
export const setUpBalanceOrder = (val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + '/purchaser/trade/recharge', 'post', val).then(res => {
			resolve(res)
		}).catch(err => {
			reject(err)
		})
	})
}

// 支付二维码
export const setQrCode = (paymentMethod, paymentClient, val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/payment/cashier/pay/${paymentMethod}/${paymentClient}/qrcode`, 'get', val)
			.then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
	})
}

// 代付信息
export const getPaymentOnBehalf = (orderSn) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/payment/cashier/behalf/pay/${orderSn}`, 'get').then(res => {
			resolve(res)
		}).catch(err => {
			reject(err)
		})
	})
}

// 聚合支付
export const polymerizationPay = (paymentMethod, paymentClient, val) => {
	return new Promise((resolve, reject) => {
		myRequest(dicts.buyer + `/purchaser/payment/cashier/pay/${paymentMethod}/${paymentClient}`, 'get', val).then(
			res => {
				resolve(res)
			}).catch((err) => {
				reject(err)
			})
	})
}